package com.liu.search.controller;

import com.liu.common.commons.PageVo;
import com.liu.search.entity.SearchMappingModel;
import com.liu.search.service.SearchMappingModelService;
import com.liu.service.base.BaseController;
import com.liu.service.vo.search.SearchRequestVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author liuxinghong
 * @Description: elasticsearch 测试接口
 * @date 2019/3/5/00510:44
 */
@RestController
@RequestMapping("/search")
@Api(tags = "检索测试")
public class SearchTestController extends BaseController {

    @Autowired(required = true)
    private SearchMappingModelService searchMappingModelService;


    @PostMapping("/save")
    @ApiOperation(value = "保存索引数据")
    public Object save(@Validated @RequestBody List<SearchMappingModel> list ){
        return success(searchMappingModelService.save(list));
    }

    /**
     * 精准分页检索(默认id倒序)
     * @return
     */
    @PostMapping("/searchPrecisePage")
    @ApiOperation(value = "精准检索分页")
    public Object searchPrecisePage(@Validated @RequestBody PageVo<SearchRequestVO> vo ){
        return success(searchMappingModelService.searchPrecise(vo));
    }

    /**
     * 分页匹配检索(默认id倒序)
     * @return
     */
    @PostMapping("/searchMatchPage")
    @ApiOperation(value = "匹配检索分页")
    public Object searchMatchPage(@Validated @RequestBody PageVo<SearchRequestVO> vo ){
        return success(searchMappingModelService.searchMatch(vo));
    }

    /**
     * 精准检索不分页
     * @return
     */
    @PostMapping("/searchPrecise")
    @ApiOperation(value = "精准检索不分页")
    public Object searchPrecise(@Validated @RequestBody SearchRequestVO vo ){

        return success(searchMappingModelService.precise(vo));
    }
    /**
     * 匹配检索不分页
     * @return
     */
    @PostMapping("/searchMatch")
    @ApiOperation(value = "匹配检索不分页")
    public Object searchMatch(@Validated @RequestBody SearchRequestVO vo ){
        return success(searchMappingModelService.match(vo));
    }
    /**
     * 详情
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "根据id查看详情")
    public Object detail(@RequestParam("id") String id){
        return success(searchMappingModelService.detail(id));
    }

    /**
     *删除
     * @return
     */
    @GetMapping("/delete")
    @ApiOperation(value = "根据id删除")
    public Object delete(@RequestParam("id") String id){
        return success(searchMappingModelService.detail(id));
    }
}


